const common = require('../../utils/common')
const { queryRejectLeadShopPage } = require('../../services/stores')
const dayjs = require('../../utils/dayjs')
const defaultPage = {
  curPage: 1,
  pageSize: 10,
}
Page({
  data: {
    total: 10,
    query: {
      ...defaultPage
    },
    dataList: [],
    loaded: false,
  },
  onLoad: function () {
    this.queryChange()
  },
  queryChange: function (payload) {
    this.setData({
      query: { ...this.data.query, ...payload }
    }, this.getDataList)
  },
  getDataList: function () {
    if (this.data.query.curPage > 1 && this.data.dataList.length >= this.data.total) return
    const params = { ...this.data.query }
    queryRejectLeadShopPage(params).then(res => {
      const { total } = res.page
      this.setData({
        total,
        loaded: true
      })
      if (params.curPage === 1) {
        this.setData({
          dataList: res.data
        })
      } else {
        this.setData({
          dataList: [...this.data.dataList, ...res.data]
        })
      }

    })
  },
  scrollBottom: function () {
    const curPage = ++this.data.query.curPage
    this.queryChange({ curPage })
  },
  goDetail: function (e) {
    const { index } = e.currentTarget.dataset;
    const item = this.data.dataList[index]
    wx.navigateTo({ url: `/pages/rejected-info/index?data=${JSON.stringify(item)}` })
  }
})
